<?php

require_once "php/config.php";

header("Content-Type: application/xslt+xml");
echo "<?xml version=\"1.0\"?>";


?><!--

@author zetta
LICENCE

I also love to hear of my work being used, feel encouraged to send an email with a link or screenshot of the design to zetaweb@gmail.com. 
This work is licensed under a Creative Commons Attribution 2.5 License. This means you may use it for any purpose, and make any changes you like. 
All I ask is that you include a link back to this page in your credits (although a giant link on every page of your website really isn't needed, contact me to discuss specifics). 

Silk icons by FAMFAMFAM (http://www.famfamfam.com/lab/icons/silk/)

           
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

  <xsl:output method="html"/>
  <xsl:template match="*"/>
  
  <xsl:template match="svn">
    <html>
      <head>
        <title>
          <xsl:if test="string-length(index/@name) != 0">
            <xsl:value-of select="index/@name"/>
            <xsl:text>: </xsl:text>
          </xsl:if>
          <xsl:value-of select="index/@path"/>
        </title>
        <link rel="stylesheet" type="text/css" href="<?php echo $path; ?>/svnindex.css"/>
        <xsl:if test="@pretty">
            <script type="text/javascript" src="<?php echo $path; ?>/jquery-1.3.2.min.js"></script>
            <script type="text/javascript" src="<?php echo $path; ?>/nsvn.js.php"></script>
        </xsl:if>
      </head>
      <body>
        <div class="header">
             <h1><xsl:text><?php echo $repoName; ?></xsl:text></h1>
        </div>
        <div class="svn">
          <xsl:apply-templates/>
        </div>
        <div class="footer">
               <xsl:element name="a">
            <xsl:attribute name="href">
               <xsl:text>http://code.google.com/p/nice-svn</xsl:text>
            </xsl:attribute>
            <xsl:text>NiceSvn</xsl:text>
         </xsl:element>
          <xsl:text> Powered by </xsl:text>
          <xsl:element name="a">
            <xsl:attribute name="href">
              <xsl:value-of select="@href"/>
            </xsl:attribute>
            <xsl:text>Subversion</xsl:text>
          </xsl:element>
          <xsl:text> </xsl:text>
          <xsl:value-of select="@version"/>
        </div>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="index">
    <div class="rev">
      <xsl:value-of select="@name"/>
      <xsl:if test="@base">
        <xsl:if test="@name">
          <xsl:text>:&#xA0; </xsl:text>
        </xsl:if>
        <xsl:value-of select="@base" />
      </xsl:if>
      <xsl:if test="@rev">
        <xsl:if test="@base | @name">
          <xsl:text> &#x2014; </xsl:text>
        </xsl:if>
        <xsl:text>Revision </xsl:text>
        <xsl:value-of select="@rev"/>
      </xsl:if>
    </div>
    <div class="path">
       <div><xsl:value-of select="@path"/></div>
    </div>
    <xsl:apply-templates select="updir"/>
    <xsl:apply-templates select="dir"/>
    <xsl:apply-templates select="file"/>
    <xsl:apply-templates select="information"/>
    <xsl:apply-templates select="code"/>    
  </xsl:template>


  <xsl:template match="updir">
    <div class="updir">
      <xsl:choose>
        <xsl:when test="@href">
            <xsl:element name="a">
            <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
            <xsl:text>Parent Directory</xsl:text>
            </xsl:element>
        </xsl:when>
        <xsl:otherwise>
          <xsl:element name="a">
            <xsl:attribute name="href">..</xsl:attribute>
            <xsl:text>Parent Directory</xsl:text>
          </xsl:element>
        </xsl:otherwise>
      </xsl:choose>
    </div>
  </xsl:template>

  

  <xsl:template match="dir">
    <div class="dir">
      <xsl:element name="a">
        <xsl:attribute name="href">
        <xsl:value-of select="@href"/>
        </xsl:attribute>
        <xsl:value-of select="@name"/>
        <xsl:text>/</xsl:text>
      </xsl:element>
    </div>
  </xsl:template>

  <xsl:template match="file">
    <div class="file">
      <xsl:element name="a">
        <xsl:attribute name="href">
          <xsl:text><?php echo $path; ?>/</xsl:text>
          <xsl:value-of select="/svn/index/@base"/>
          <xsl:value-of select="/svn/index/@path"/>
          <xsl:text>/</xsl:text>
          <xsl:value-of select="@href"/>
        </xsl:attribute> 
          <xsl:value-of select="@name"/>
      </xsl:element>
    </div>
  </xsl:template>


  <xsl:template match="code">
    <div class="code loading" id="code">
       <xsl:element name="span"><xsl:attribute name="id">codeUrl</xsl:attribute><xsl:value-of select="@src"/></xsl:element>
       <div id="prettyCode"></div>
    </div>
  </xsl:template>
  
  <xsl:template match="information">
    <div class="information" id="informationBox">
      <div class="rev" id="toggleDetails">Details</div>
      <div class="path">
         <xsl:element name="p">
           r<xsl:value-of select="@last-changed-rev"/> by
             <xsl:choose>
               <xsl:when test="@last-changed-author">
                 <xsl:value-of select="@last-changed-author"/>
               </xsl:when>
               <xsl:otherwise>
                 (no author)
               </xsl:otherwise>
             </xsl:choose>
             on <xsl:value-of select="@last-changed-date"/>
            </xsl:element>
      </div>  
      
      <div class="content" id="contentDetails">   
         <h4>Previous Revisions:</h4>
         <ul id="revision-list">
         <xsl:for-each select="/svn/index/revisions/revision">
            <xsl:element name="li">
              <xsl:if test="position() &gt; 5">
                <xsl:attribute name="class">hidden</xsl:attribute>
              </xsl:if>
              <xsl:element name="a">
              <xsl:attribute name="class">hiddenRevision</xsl:attribute>
              <xsl:attribute name="href">#<xsl:value-of select="@number" /></xsl:attribute>
                <xsl:value-of select="@number" />
              </xsl:element>
              by <xsl:value-of select="@by" /> 
              on <xsl:value-of select="@on" />
              <xsl:if test="@prev != 0">
                 <xsl:element name="a">
                 <xsl:attribute name="class">diffTrigger</xsl:attribute>
                 <xsl:attribute name="href">#<xsl:value-of select="@number" />/<xsl:value-of select="@prev" /></xsl:attribute>
                   Diff
                 </xsl:element>
              </xsl:if>
            </xsl:element>
         </xsl:for-each>
         </ul>
         <hr/>
        <h4>File Properties</h4>
           <ul>
             <xsl:for-each select="/svn/index/properties/property">
               <li><strong><xsl:value-of select="@name"/></strong>
                  <ul>
                      <xsl:for-each select="value">
                      <li> <xsl:value-of select="@value" /></li>
                      </xsl:for-each>
                  </ul>
               </li>
             </xsl:for-each>
           </ul>
        
        <hr/>
        <h4>Raw File</h4>
        <xsl:element name="a">
            <xsl:attribute name="href"><xsl:value-of select="/svn/index/information/@raw"/></xsl:attribute>        
            <xsl:value-of select="/svn/index/information/@name"/>
        </xsl:element>
        
      </div>
    </div>
  </xsl:template>


</xsl:stylesheet>


